<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility"%>
<%@ include file="/public/header.jsp"%>

<html>
<head>
<title>工单管理</title>
</head>
<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$('#gd_status').combobox({
				 url:'<%=contextPath%>/springMVC/gd/listGDStatus',
				 valueField:'id',
				 textField:'text',
				 onChange:function(){
						doSearch();
					}
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});

			jQuery("#searchValue2").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch2();
		       	} 
		   	}); 
			jQuery('#gd_admin_id').combogrid({
				title:'派单人选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tba",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch2();
				}
			});
			$("#table").datagrid({
				title:"已关闭工单",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath%>/springMVC/gd/listPageGDBase?flagType=2',
				rownumbers:true,
				singleSelect:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'项目id',field:'xm_id',hidden:true},
				    {title:'项目编号',field:'xm_code',hidden:true},
				    {title:'项目名称',field:'xm_name',hidden:true},
				    {title:'客户id',field:'customer_id',hidden:true},
				    {title:'客户',field:'customer',hidden:true},
				    {title:'所属部门id',field:'dept_id',hidden:true},
				    {title:'最新的工单内容id',field:'gd_content_id',hidden:true},
				    {title:'工单类型',field:'gd_type',hidden:true}
				]],
				columns:[[
					{title:'工单状态',field:'gd_status',hidden:true},
					{title:'工单进度',field:'gd_status_desc',width:80,align:'center'},
					{title:'派单人',field:'gd_admin_name',width:80,align:'center'},
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:200,align:'center'},
					//{title:'创建日期',field:'gd_create_time',width:150,align:'center'},
					{title:'完工日期',field:'gd_actual_end',width:150,align:'center'},
					{title:'关闭日期',field:'gd_close_time',width:150,align:'center'},
// 					{title:'变更次数',field:'gd_content_num',width:50,align:'center',formatter:function(value){
// 						return value-1;
// 					}},
					{title:'材料',field:'material',width:40,align:'center',formatter:function(value,rowData,rowIndex){
	                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-kcpd'  onclick=\"javascript:materialManage('"+rowData.id+"','"+rowData.gd_content_id+"','"+rowData.dept_id+"','"+rowData.dept_name+"','"+rowData.gd_code+"','"+rowData.gd_name+"','"+rowData.customer_id+"','"+rowData.customer+"');\"/>";
					}},
					{title:'财务',field:'finance',width:40,align:'center',formatter:function(value,rowData,rowIndex){
	                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-pur_payment2'  onclick=\"javascript:addOrEditLoan('"+rowData.id+"','"+rowData.dept_id+"','"+rowData.dept_name+"','"+rowData.gd_code+"','"+rowData.gd_name+"');\"/>";
					}},
					{title:'进程',field:'process',width:40,align:'center',formatter:function(value,rowData,rowIndex){
	                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-kcdb'  onclick=\"javascript:addProcess('"+rowData.id+"','"+rowData.gd_name+"','"+rowData.gd_code+"');\"/>";
					}},
					{title:'安质',field:'quality',width:40,align:'center',formatter:function(value,rowData,rowIndex){
	                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-base'  onclick=\"javascript:securityCheck('"+rowData.id+"','"+rowData.gd_name+"','"+rowData.gd_code+"');\"/>";
					}},
					{title:'发起核算',field:'adjust_accounts',width:60,align:'center',formatter:function(value,rowData,rowIndex){
		                return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' title='核算明细' class='icon-transfer'  onclick=\"javascript:startAccounting('"+rowData.gd_status+"','"+rowData.id+"','"+rowData.gd_content_id+"','"+rowData.gd_name+"','"+rowData.gd_code+"','"+rowData.xm_name+"','"+rowData.xm_code+"');\"/>";
					}},
					{title:'成本固化',field:'close_gd',width:60,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.gd_type==1){
		                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_BALANCE_SHENPI_W%>")+"','"+rowData.id+"');\"/>";
						}else{
		                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_BALANCE_SHENPI%>")+"','"+rowData.id+"');\"/>";
						}
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var gd_id = row.id;
					var gd_status = row.gd_status;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'内容明细',
						url:'<%=contextPath%>/springMVC/gd/listGDContent?gd_id='+gd_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'内容id',field:'id',hidden:true},
							{title:'编号',field:'gd_content_code',hidden:true},
							{title:'',field:'desc',width:100,align:'center',formatter:function(value,row){
								
								if(row.gd_content_code == '1'){
									return "原始内容";
								}else{
									return "第"+(row.gd_content_code-1)+"次变更内容";
								}
							}},
							{title:'当前状态',field:'status',hidden:true},
							{title:'当前状态',field:'status_desc',width:100,align:'center'},
							{title:'工单内容',field:'content',width:150,align:'center'},
							{title:'工时',field:'gd_total_time',width:50,align:'center'},
							{title:'要求日期（起始）',field:'gd_start',width:100,align:'center'},
							{title:'要求日期（截止）',field:'gd_will_end',width:100,align:'center'},
							{title:'收单单位',field:'gd_worker_name',width:100,align:'center'},
							{title:'现场交底',field:'more',width:50,align:'center',formatter:function(value,rowData,rowIndex){
								if(rowData.status == '<%=com.beaut.project.util.StaticData.PASS%>'){
			                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-customerGroup' title='现场交底' onclick=\"javascript:gdDescription('"+gd_id+"','"+rowData.id+"','"+row.gd_name+"','"+row.gd_code+"','"+row.gd_status+"','"+rowData.gd_content_code+"','"+row.gd_content_num+"');\"/>";
								}
							}},
							{title:'审批查看',field:'shenpichakan',width:50,align:'center',formatter:function(value,rowData,rowIndex){
								if(rowData.status != '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
									return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_SHENPI%>")+"','"+rowData.id+"');\"/>";
								}
								return "";
					        }},
							{title:'操作',field:'edit',width:80,align:'center',formatter:function(value,rowData,rowIndex){
								return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='内容详情' onclick=\"javascript:showGD('"+gd_id+"','"+rowData.id+"');\"/>";
							}}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function assume(gd_id){
			openDialogResize("<%=contextPath%>/springViews/gd/gdAssumeManage.jsp?is_closed=1&gd_id="+gd_id,1000, 800);
		}
		function materialManage(gd_id,gd_content_id,dept_id,dept_name,gd_code,gd_name,customer_id,customer){
			var param = 'is_closed=1&customer_id='+customer_id+'&customer='+encodeURIComponent(customer)+'&gd_id='+gd_id+'&gd_content_id='+gd_content_id+'&dept_id='+dept_id+'&dept_name='+encodeURIComponent(dept_name)+'&gd_code='+encodeURIComponent(gd_code)+'&gd_name='+encodeURIComponent(gd_name);
			openDialogResize("<%=contextPath%>/springViews/gd/gdMaterialManage.jsp?"+param,1000, 800);
		}
		function addOrEditLoan(gd_id,dept_id,dept_name,gd_code,gd_name){
			var param = 'is_closed=1&gd_id='+gd_id+'&dept_id='+dept_id+'&dept_name='+encodeURIComponent(dept_name)+'&gd_code='+encodeURIComponent(gd_code)+'&gd_name='+encodeURIComponent(gd_name);
			openDialogResize("<%=contextPath%>/springViews/gd/gdLoanOrAdvances.jsp?"+param,1000, 800);
		}
		
		function gdDescription(gd_id,gd_content_id,gd_name,gd_code,gd_status,gd_content_code,gd_content_num){
			openDialogResize('<%=contextPath%>/springViews/gd/gdDescription.jsp?callback=rtCallBack&gd_id='+gd_id+'&gd_content_id='+gd_content_id+'&gd_name='+gd_name+'&gd_code='+gd_code+'&gd_status='+gd_status+'&gd_content_code='+gd_content_code+'&gd_content_num='+gd_content_num,1000, 800);
		}
		function showGD(gd_id,gd_content_id){
			openDialogResize('<%=contextPath%>/springViews/gd/showGd.jsp?gd_id='+gd_id+'&gd_content_id='+gd_content_id,1000, 800);
		}
		//添加进程
		function addProcess(gd_id,gd_name,gd_code){
			openDialogResize('<%=contextPath%>/springViews/gd/processManage.jsp?is_closed=1&gd_id='+gd_id+'&gd_name='+gd_name+'&gd_code='+gd_code,1000, 800);

		}
		//安质检查
		function securityCheck(gd_id,gd_name,gd_code){
			openDialogResize('<%=contextPath%>/springViews/gd/securityCheckManage.jsp?is_closed=1&gd_id='+gd_id+'&gd_name='+gd_name+'&gd_code='+gd_code,1000, 800);
		}
		//发起核算
		function startAccounting(status,gd_id,gd_content_id,gd_name,gd_code,xm_name,xm_code){
			openDialogResize('<%=contextPath%>/springViews/gd/gdAccounting.jsp?status='+status+'&gd_id='+gd_id+'&gd_content_id='+gd_content_id+'&gd_name='+gd_name+'&gd_code='+gd_code+'&xm_name='+xm_name+'&xm_code='+xm_code,2000, 1000);
		}
		function doSearch2() {
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			var searchValue = jQuery('#searchValue2').val();
			jQuery('#gd_admin_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
	function doSearch() {
		var searchValue = $('#searchValue').val();
		var gd_status = $('#gd_status').combobox('getValue');
		var dept_id = $("#dept_id").combotree('getValue');
		var gd_admin_id = jQuery("#gd_admin_id").combotree('getValue');
		$('#table').datagrid('load', {
			searchValue : searchValue,
			dept_id : dept_id,
			gd_status : gd_status,
			gd_admin_id:gd_admin_id
		});
	}
</script>
<body style="height: 97%">
	<div id="table" data-options="fit:true"></div>
	<div id="tb" style="padding:3px;height:auto">
		<div align="right">
			派单人：<input type="text" id="gd_admin_id" name="gd_admin_id"   style="width:100px"> &nbsp;&nbsp;
			所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
			<div style="display:none;">工单进度：<input id="gd_status" name="gd_status" />&nbsp;&nbsp;</div> 
			工单编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="工单编号/名称" placeholder="工单编号/名称 "/>&nbsp;&nbsp; 
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
	<div id="tba" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue2" name="searchValue2" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch2();"></a>
			</div>
		</div>
</body>
</html>
